var express = require('express');
var router = express.Router();
var db = require("../config/db"); //引入数据库封装模块

// 首页
router.get('/index', function(req, res, next) {
  console.log(req.session.username)
  if(req.session.username){
		res.render('index',{
			isLogin: true,
			username: req.session.username
		});
	}else {
		res.render('index',{
			isLogin:false
		});
	}
  // res.render('index', { isLogin: true });
});
// 登录
router.get('/login', function(req, res, next) {
  res.render('login');
});
// 注册
router.get('/reg', function(req, res, next) {
  res.render('reg');
});
// 个人中心
router.get('/center',function(req,res) {
	res.render('center');
});
// 开始游戏
router.get('/play',function(req,res) {
	db.query(`SELECT * FROM boxes`, [], function (results) {
		res.render('play',{list: results});
	})
});
// 兑换奖品
router.get('/info',function(req,res) {
	var user = req.session.username;
	db.query(`SELECT * FROM my_goods WHERE user="${user}"`, [], function (results) {
		res.render('info',{goodList: results});
	})
});
// 后台
router.get('/admin',function(req,res) {
	db.query(`SELECT * FROM goods`, [], function (results) {
		res.render('admin', {goodList: results});
	})
});
module.exports = router;
